﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FriendAnalyzer.TestMocks;
using Windows.UI;
using FriendAnalyzer.Infrastructure.Facebook.Model;
namespace FriendAnalyzer.Graph
{
    public class StatisticDataConverter
    {
        static Dictionary<FacebookUser, FacebookUser[]> cachedAlgorithm = null; 
        public static async Task<Graph.Diagram> BuildGraphNodes(uint centers,Business.AggregateService service,bool fromScratch)
        {

            var mDiagram = new Graph.Diagram();
           // var test = ProcessedMatrixProvider.GetRandomFriendNodes(10, centers);
            //var service = new FriendAnalyzer.Business.AggregateService();
            if (cachedAlgorithm == null || fromScratch)
            {
                cachedAlgorithm = await service.GetGroupedFacebookUsers(centers, 0.00005, 2.0, 200);
            }
           // var test = await service.GetGroupedFacebookUsers(centers,0.00005,2.0,200);
            foreach (var c in cachedAlgorithm.Keys)
            {
                SpotNode Leader = new SpotNode(Colors.Red,c.LastName + " " + c.FirstName,c.UserID.ToString());
                mDiagram.AddNode(Leader);
                //List<FacebookUser> children = new List<FacebookUser>();
                var children = new FacebookUser[10000];
                if (cachedAlgorithm.TryGetValue(c, out children))
                {
                    foreach (var child in children)
                    {
                       
                            SpotNode childDrawing = new SpotNode(Colors.Green, child.LastName + " " + child.FirstName, child.UserID.ToString());
                            Leader.AddChild(childDrawing);
                  
                    }
                }
            }
            return mDiagram;
        }
    }
}
